﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JzSport.Api
{
    class GetActivityImageListAction : GetAction<Params.GetActivityImageListParams,
        Results.GetActivityImageListResult>
    {
        protected override ActionResult<Results.GetActivityImageListResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            Params.GetActivityImageListParams opParams)
        {
            ServiceResult<List<ImageResource>> serviceResult = new ActivityService().GetActivityImageList(opParams.ActivityId);

            Results.GetActivityImageListResult actionResult = new Results.GetActivityImageListResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                for (int index = 0; index < serviceResult.Data.Count; index++)
                {
                    Results.GetActivityImageListResult.ImageItem item = new Results.GetActivityImageListResult.ImageItem();
                    item.Id = serviceResult.Data[index].Id;
                    item.Url = string.Format("{0}{1}", Configs.BaseWebUrl, serviceResult.Data[index].Url);

                    actionResult.Add(item);
                }
                return new ActionResult<Results.GetActivityImageListResult>("1.0.1", true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.GetActivityImageListResult>("1.0.1", false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
